﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using QXBook.Model;
using QXBook.Service;
using System.Text;
using QXBook.Utils;

namespace Web.App_Code
{
    public class UserBasePage : System.Web.UI.Page
    {
        public UserBasePage()
        { 
        }

        public UsersInfo userInfo
        {
            get
            {
                if (this._userInfo == null)
                {
                    this._userInfo = ServiceFactory.CreateInstance<UsersService>().GetUsersInfo();
                }
                return this._userInfo;
            }
        }
        private UsersInfo _userInfo = null;

        /// <summary>
        /// AJAX输出字符串
        /// </summary>
        public string ajaxdata
        {
            get
            {
                return this._ajaxdata;
            }
            set
            {
                this._ajaxdata = value;
            }
        }

        private string _ajaxdata = string.Empty;

        protected void ResponseErch(string str)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alert('" + str + "')</script>");
        }

        protected void ResponseErch(string str, string okmessage)
        {
            if (!string.IsNullOrEmpty(okmessage))
            {
                this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alert('" + okmessage + "')</script>");
            }
            else
            {
                this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alert('" + str + "')</script>");
            }
        }

        protected void AjaxErch(string str)
        {
            Response.ContentType = "application/x-javascript";
            Response.Write(str);
            Response.End();
        }

        /// <summary>
        /// 判断数据库执行参数
        /// </summary>
        /// <param name="rtn"></param>
        /// <param name="okmessage"></param>
        protected void AjaxErch(string refmessage, string okmessage)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("{state:");
            if (!string.IsNullOrEmpty(refmessage))
            {
                sb.Append("false,message:\"" + refmessage + "\"");
            }
            else
            {
                sb.Append("true,message:'" + okmessage + "'");
            }
            sb.Append("}");
            Response.ContentType = "application/x-javascript";
            Response.Write(sb.ToString());
            Response.End();
        }

        protected void AjaxErch(string refmessage, string okmessage, string callback)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("{state:");
            if (!string.IsNullOrEmpty(refmessage))
            {
                sb.Append("false,message:\"" + refmessage + "\"");
            }
            else
            {
                sb.Append("true,message:\"" + okmessage + "\",callback:\"" + callback + "\"");
            }
            sb.Append("}");
            Response.Write(sb.ToString());
            Response.End();
        }
    }
}